package cn.sdhuijin.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * 机构实体类
 * 
 * @author sunp@sdhuijin.cn
 * @version 创建时间：2014年12月24日 下午5:20:57
 */
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@Entity
@Table(name = "branch")
public class Branch extends IdEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	// 机构名称
	@NotEmpty(message = "机构名称不能为空")
	private String name;
	// 机构地址
	private String address;
	// 负责人
	private String head;
	// 联系电话
	private String phone;
	// 备注
	private String remarks;
	// 父节点
	@ManyToOne
	@JoinColumn(name = "parent_id")
	private Branch parent;
	// 子节点
	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "parent", fetch = FetchType.LAZY)
	private List<Branch> children;
	// 关联的用户
	@OneToMany(cascade = { CascadeType.REFRESH }, mappedBy = "branch", fetch = FetchType.EAGER)
	private List<User> users;
	// 创建时间
	private Date createDate;
	// 修改时间
	private Date modifyDate;

	/**
	 * @return the createDate
	 */
	public Date getCreateDate() {
		return createDate;
	}

	/**
	 * @param createDate
	 *            the createDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	/**
	 * @return the modifyDate
	 */
	public Date getModifyDate() {
		return modifyDate;
	}

	/**
	 * @param modifyDate
	 *            the modifyDate to set
	 */
	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * @param address
	 *            the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the head
	 */
	public String getHead() {
		return head;
	}

	/**
	 * @param head
	 *            the head to set
	 */
	public void setHead(String head) {
		this.head = head;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @param phone
	 *            the phone to set
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * @return the remarks
	 */
	public String getRemarks() {
		return remarks;
	}

	/**
	 * @param remarks
	 *            the remarks to set
	 */
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	/**
	 * @return the parent
	 */
	public Branch getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(Branch parent) {
		this.parent = parent;
	}

	/**
	 * @return the children
	 */
	@JsonIgnore
	public List<Branch> getChildren() {
		return children;
	}

	/**
	 * @param children
	 *            the children to set
	 */
	@JsonIgnore
	public void setChildren(List<Branch> children) {
		this.children = children;
	}

	/**
	 * @return the users
	 */
	@JsonIgnore
	public List<User> getUsers() {
		return users;
	}

	/**
	 * @param users
	 *            the users to set
	 */
	@JsonIgnore
	public void setUsers(List<User> users) {
		this.users = users;
	}

}
